﻿using System;
using System.Text.RegularExpressions;

namespace FluentParser.Utils
{
    internal static class NumberHelper
    {
        public static Int16? TryParseInt16(string text)
        {
            Int16 value;
            if (Int16.TryParse(text, out value))
                return value;

            return null;
        }

        public static UInt16? TryParseUInt16(string text)
        {
            UInt16 value;
            if (UInt16.TryParse(text, out value))
                return value;

            return null;
        }

        public static Int32? TryParseInt32(string text)
        {
            Int32 value;
            if (Int32.TryParse(text, out value))
                return value;

            return null;
        }

        public static UInt32? TryParseUInt32(string text)
        {
            UInt32 value;
            if (UInt32.TryParse(text, out value))
                return value;

            return null;
        }

        public static Int64? TryParseInt64(string text)
        {
            Int64 value;
            if (Int64.TryParse(text, out value))
                return value;

            return null;
        }

        public static UInt64? TryParseUInt64(string text)
        {
            UInt64 value;
            if (UInt64.TryParse(text, out value))
                return value;

            return null;
        }

        private static readonly Regex RegexSignedNatural = new Regex("\\G-?[0-9]+");
        private static readonly Regex RegexSignedReal = new Regex("\\G-?[0-9]+(\\.[0-9]+)");
        private static readonly Regex RegexUnsignedNatural = new Regex("\\G[0-9]+");
        private static readonly Regex RegexUnsignedReal = new Regex("\\G[0-9]+(\\.[0-9]+)");
    }
}